package com.sgb.member.view_model;

import com.sgb.member.MemberConfig;
import com.sgb.member.di.repository.MemberRepertory;
import com.sgb.member.ui.fragment.MemberBusinessFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

public class MemberBusinessFragModel extends BaseViewModel {

    private final MemberBusinessFragment fragment;
    private final MemberRepertory mRepertory;

    private CommonPopEntity mAll;

    public MemberBusinessFragModel(MemberBusinessFragment fragment, MemberRepertory repertory) {
        this.fragment = fragment;
        this.mRepertory = repertory;

        mAll = new CommonPopEntity();
        mAll.setNo("");
        mAll.setTypeName("全部");
    }

    public void showOrHideDialog(boolean aBoolean) {
        if (aBoolean) {
            if (!DialogHelper.isShowing()) {
                DialogHelper.showProgressDialog(fragment.getActivity(), "数据获取中...");
            }
        } else {
            DialogHelper.dismissProgressDialog();
        }
    }

    // 经营商品行业分类
    public void getGoodsCategory(int type) {
        showOrHideDialog(true);
        mRepertory.getApi().getIndustryList().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    data.getData().add(0, mAll);
                    fragment.setTabLayoutData(data.getData());
                } else {
                    fragment.setTabLayoutData(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CommonPopEntity>>> call, Throwable t) {
                super.onFailure(call, t);
                fragment.setTabLayoutData(new ArrayList<>());
            }


            @Override
            public void onFinally() {

            }
        });
    }

    // 会员商品
    public void getGoodsType() {
        List<CommonPopEntity> list = new ArrayList<>();
        list.add(new CommonPopEntity("0", "供方会员报价"));
        list.add(new CommonPopEntity("1", "公司经营"));
        fragment.setTabLayoutData(list);
    }


    // 会员招采  v1.1.1 同步会员经营——招采全部数据；筛选显示【一级分类】
    public void getPickType() {
        List<CommonPopEntity> list = new ArrayList<>();
        list.add(new CommonPopEntity("", "全部"));
        list.add(new CommonPopEntity("0", "招标公告"));
        list.add(new CommonPopEntity("1", "直接竞价"));
        list.add(new CommonPopEntity("2", "招标预告"));
        fragment.setTabLayoutData(list);
    }

    public void getWuliuType() {
        List<CommonPopEntity> list = new ArrayList<>();
        if (MemberConfig.getInstance().getComType() == MemberConfig.WEBSITE_FOR_PERSONAL) {
            list.add(new CommonPopEntity("0", "个人货运"));
        }else {
            list.add(new CommonPopEntity("0", "公司货运"));
        }
        list.add(new CommonPopEntity("1", "会员货运"));
        list.add(new CommonPopEntity("2", "管理车辆"));
        if (MemberConfig.getInstance().getComType() == MemberConfig.WEBSITE_FOR_PERSONAL) {
            list.add(new CommonPopEntity("3", "个人长期需求货车"));
        }else {
            list.add(new CommonPopEntity("3", "公司长期需求货车"));
        }
        fragment.setTabLayoutData(list);
    }

    // 会员集采
    public void getCollectingType() {
        List<CommonPopEntity> list = new ArrayList<>();
        list.add(new CommonPopEntity("0", "需方发起"));
        list.add(new CommonPopEntity("1", "供方发起"));
        list.add(new CommonPopEntity("2", "企业专项"));
        fragment.setTabLayoutData(list);
    }
    /*
    // 会员集采
    public void getCollectingType() {
        showOrHideDialog(true);
        mRepertory.getApi().groupBuyClassList().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    data.getData().add(0, mAll);
                    fragment.setTabLayoutData(data.getData());
                } else {
                    fragment.setTabLayoutData(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CommonPopEntity>>> call, Throwable t) {
                super.onFailure(call, t);
                fragment.setTabLayoutData(new ArrayList<>());
            }
        });
    }*/

    // 会员租赁
    public void getLeaseType() {
        List<CommonPopEntity> list= new ArrayList<>();
        list.add(new CommonPopEntity("1", "供方出租"));
        fragment.setTabLayoutData(list);
    }

    // 会员工队
    public void getPackerType() {
        //  1施工队 2班组
        List<CommonPopEntity> list = new ArrayList<>();
        list.add(new CommonPopEntity("0", "施工队"));
        list.add(new CommonPopEntity("1", "班组工队"));
        list.add(new CommonPopEntity("3", "工种报价"));
        fragment.setTabLayoutData(list);
    }

    // 物流货物
    public void getLogisticsType() {
        showOrHideDialog(true);
        mRepertory.getApi().getAllLogisticsGoodsType().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    data.getData().add(0, new CommonPopEntity("", "不限"));
                    fragment.setTabLayoutData(data.getData());
                } else {
                    fragment.setTabLayoutData(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CommonPopEntity>>> call, Throwable t) {
                super.onFailure(call, t);
                fragment.setTabLayoutData(new ArrayList<>());
            }

            @Override
            public void onFinally() {

            }
        });
    }


    // 企业服务
    public void getEnterpriseServicesType() {
        showOrHideDialog(true);
        mRepertory.getApi().getAllEnterpriseServicesType().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                showOrHideDialog(false);
                if (data.getData() != null && data.getData() != null && data.getData().size() > 0) {
                    data.getData().add(0, new CommonPopEntity("", "全部"));
                    fragment.setTabLayoutData(data.getData());
                } else {
                    fragment.setTabLayoutData(new ArrayList<>());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CommonPopEntity>>> call, Throwable t) {
                super.onFailure(call, t);
                fragment.setTabLayoutData(new ArrayList<>());
            }

        });
    }
}
